// 云函数入口文件
const cloud = require('wx-server-sdk');
const _ = require('lodash');
const uuid = require('short-uuid');

cloud.init();
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const code_list = [];
  const data_list = [];
  while (code_list.length < 300) {
    const code = uuid.generate();
    if (!code_list.includes(code)) {
      code_list.push(code);
      data_list.push({ code });
    }
  }
  await db.collection('lottery_code').add({ data: data_list });
  return { message: 'OK', quantity: code_list.length }
}